package com.xinqi.modules.sys.dict.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.dict.dto.req.SchoolCreateDTO;
import com.xinqi.modules.sys.dict.dto.req.SchoolQueryDTO;
import com.xinqi.modules.sys.dict.dto.req.SchoolUpdateDTO;
import com.xinqi.modules.sys.dict.dto.rsp.SchoolResultDTO;
import com.xinqi.modules.sys.dict.service.SchoolService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学校表APP控制层
 *
 * @author: wenjie
 * @date: 2023/05/19
 */
@Tag(name = "App-学校表", description = "学校表App接口")
@RestController
@RequestMapping("/app/school")
@RequiredArgsConstructor
public class SchoolAppController {
    private final SchoolService schoolService;

    /**
     * 学校表-分页
     */
    @Operation(summary = "学校表-分页")
    @GetMapping("/page")
    public R<PageInfo<SchoolResultDTO>> page(@ParameterObject SchoolQueryDTO dto) {
        PageInfo<SchoolResultDTO> page = schoolService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 学校表-详情
     */
    @Operation(summary = "学校表-详情")
    @GetMapping("/{id}")
    public R<SchoolResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        SchoolResultDTO dto = schoolService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增学校表
     */
    @Operation(summary = "新增学校表")
    @PostMapping
    public R<Long> insert(@RequestBody SchoolCreateDTO dto) {
        return R.data(schoolService.insert(dto));
    }

    /**
     * 修改学校表
     */
    @Operation(summary = "修改学校表")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody SchoolUpdateDTO dto) {
        dto.setId(id);
        return R.data(schoolService.updateById(dto));
    }

    /**
     * 删除学校表
     */
    @Operation(summary = "删除学校表")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(schoolService.deleteById(id));
    }
}
